package com.jiyinit.web.core.business.dao;

import com.jiyinit.core.framework.base.paging.PagingResult;
import com.jiyinit.core.framework.dao.mybatis.base.MybatisDaoContext;
import com.jiyinit.core.framework.dao.mybatis.paginator.domain.PageBounds;
import com.jiyinit.web.core.business.dto.FunRolePageRequest;
import com.jiyinit.web.core.business.entity.TabFunRoleEntity;
import com.jiyinit.web.core.business.vo.FunctionRoleVo;
import org.apache.ibatis.jdbc.SQL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <p></p>
 * <p/>
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *
 * @author zhaolaiwei
 * @version 1.0
 * @date 2017/4/11 17:51
 * @since 1.0
 */
@Repository("core.tabFunRoleDao")
public class TabFunRoleDao {

    /**
     * 日志对象
     */
    private static Logger logger = LoggerFactory.getLogger(TabFunRoleDao.class);

    private String SQLID = "function.role.";

    @Autowired
    @Qualifier("core.MybatisDaoContext")
    private MybatisDaoContext mybatisDaoContext;

    public PagingResult<FunctionRoleVo> findByPage(Integer orgId,FunRolePageRequest funRolePageRequest){
        PageBounds pageBounds = new PageBounds();
        pageBounds.setLimit(10);
        pageBounds.setPage(funRolePageRequest.getPage());
        Map map = funRolePageRequest.toMap();
        map.put("orgId",orgId);
        return mybatisDaoContext.findForPage(SQLID+"findByPage",FunctionRoleVo.class,map,pageBounds);
    }

    public int add(TabFunRoleEntity entity){
        return mybatisDaoContext.save(SQLID+"insertSelective",entity);
    }

    public TabFunRoleEntity findById(Integer funRoleId){
        return mybatisDaoContext.findOne(SQLID+"findById",TabFunRoleEntity.class,funRoleId);
    }

    public int update(TabFunRoleEntity entity){
        return mybatisDaoContext.update(SQLID+"updateByPrimaryKeySelective",entity);
    }

    public List<TabFunRoleEntity> findByIds(Integer[] funRoleIds){
        return mybatisDaoContext.findAll(SQLID+"findByIds",TabFunRoleEntity.class,funRoleIds);
    }
   public int delete(List<TabFunRoleEntity> list){
       return mybatisDaoContext.batchUpdate(SQLID+"updateByPrimaryKeySelective",list);
   }
}
